<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%@ include file="/common/grid/jqGrid.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="">
	<meta http-equiv="description" content="This is my page">
	
  </head>
  
  <body>
    <center>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		userId: <input type="text" id="userId" class="search" />
    		<%--
    		&nbsp;
    		sex: <s:radio list='#{"":"全部","男":"男","女":"女"}' name="uvo.user.sex" cssClass="search" />
    		--%>
    		&nbsp;
    		<input name="sex" type="checkbox" value="男" class="search" /> 男
    		<input name="sex" type="checkbox" value="女" class="search" /> 女
    		<table id="list" class="scroll"></table>
			<div id="pager" class="scroll" style="text-align:center;"></div>
			
			<input type="button" value="search" onclick="refreshTb()" />
			<input type="button" value="reset" onclick="resetSearch()" />
			<input type="button" value="check" onclick="checks()" />
    	</s:form>
    </center>
    
    <script type="text/javascript">
    $(document).ready(function(){
    	var cName = new Array('Id','Username', 'Password', 'Department');
    	var cModel = [ {name:'id', index:'id', width:'20%', align:'center'},
                        {name:'username', index:'username', width:'30%', align:'center'},
                        {name:'password', index:'password', width:'30%', align:'center'},
                        {name:'deptName', index:'deptName', width:'20%', align:'center'}
                      ];
        $("#list").jqGrid({
            datatype:'json',
            mtype:'POST',
            url : realPath + '/test/userManage.action',
			width:700,
            height:500,
            colNames:cName,
            colModel :cModel,
            rowNum:5,
            rowList:[5,10,20,30],
            jsonReader : {
                root: "list",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: false,
                id: "id"
            },
            pager: '#pager',
            caption: 'My first grid',
            multiselect: true,
            viewrecords:true,
            gridview: true,
            onSelectRow: function(id){
            				
            			}
        }).navGrid('#pager',{view:true,edit:false,add:true,del:false,search:false});
		
		$('#list').navButtonAdd('#pager',{ caption:"search", buttonicon:"ui-icon-newwin", onClickButton:showSearch, position: "last", title:"", cursor: "pointer"});
    });
    
    function refreshTb()
    {
    	var searchObj = {
    		'uvo.user.id':$('#userId').val(),
    		'uvo.user.sex':multiToString('sex', 'checkbox')
    	};
    	searchThis('#list', searchObj);
    }

    function checks()
    {
    	var cb = $('#list input:checkbox[checked]');
    	for(var i = 0; i < cb.length; i++)
    	{
    		var cbx = $(cb.get(i));
    		alert(cbx.attr('value'));
    	}
    }
    
    function showSearch()
    {
    	$('#list').jqGrid("searchGrid", {  
	        caption: "查找",
	        Find: "Go!",
	        closeAfterSearch: true,
	        multipleSearch: true,
	        groupOps: [{ op: "AND", text: "全部" }]
	    });
    }
    
    function searchThis(gridId, searchJson)
    {
    	if(gridId != null && gridId.indexOf('#') > -1)
    	{
    		gridId = gridId.substring(1);
    	}
    	else
    	{
    		showMsg('查询不正确。');
    		return;
    	}
    	if(searchJson == undefined)
    	{
    		searchJson = '';
    	}
    	$("#" + gridId).jqGrid().setGridParam({
        	postData: searchJson
        }).trigger("reloadGrid", [{page:1}]);
    }
    
    function getCbArray(cbName)
    {
    	var cb = $('input:checkbox[name="' + cbName + '"][checked]');
    	var arr = new Array();
    	for(var i = 0; i < cb.length; i++)
    	{
    		arr.push($(cb.get(i)).val());
    	}
    	return arr;
    }
    
    </script>
  </body>
</html>
